Skip to content

fix: Entity::normalizeValue() must handle UnitEnum before toArray() #10137

Open
maniaba wants to merge 1 commit intocodeigniter4:developfrom
maniaba:bug-entity
Open

fix: Entity::normalizeValue() must handle UnitEnum before toArray() #10137
maniaba wants to merge 1 commit intocodeigniter4:developfrom
maniaba:bug-entity

Conversation

@maniaba
Copy link
Copy Markdown
Contributor

@maniaba maniaba commented Apr 24, 2026

Description

Moves the UnitEnum instanceof check before JsonSerializable and method_exists($data, 'toArray') in Entity::normalizeValue(), so that enums implementing toArray() are always normalized as enums rather than as generic objects.

Fixes #10136

  • fix test: correct toRawArray() assertion for injected enum

toRawArray() returns raw $this->attributes, so an injected enum object stays as an enum object — not the backing string value. The real regression is that hasChanged() must return false (normalizeValue() handles UnitEnum before toArray()).

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@patel-vansh
Copy link
Copy Markdown
Contributor

You need to add this fix in v4.7.3 changelog

Comment thread tests/_support/Enum/StateEnum.php
Comment thread tests/system/Entity/EntityTest.php
@github-actions github-actions Bot added the stale Pull requests with conflicts label Apr 26, 2026
@github-actions
Copy link
Copy Markdown

👋 Hi, @maniaba!

We detected conflicts in your PR against the base branch 🙊
You may want to sync 🔄 your branch with upstream!

Ref: Syncing Your Branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Pull requests with conflicts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Entity::normalizeValue incorrectly handles enums when they implement toArray()

3 participants